﻿using AutoMapper.Internal.Mappers;
using EMS.system.Entityies.MasterData.MaterialManagementModel;
using EMS.system.Entityies.MasterData.MaterialTypeModel;
using EMS.system.IEntityAppService.MasterData.MaterialManagementService;
using EMS.system.IEntityAppService.MasterData.MaterialManagementService.MaterialManagementDTO;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace EMS.system.Web.Controllers.MasterData.MaterialManagements
{
    public class MaterialManagementController : Controller
    {
        IMaterialManagementAppService _service;

        public MaterialManagementController(IMaterialManagementAppService server)
        {
            _service = server;
        }


        public IActionResult MaterialSel()
        {
            return View();
        }

        /// <summary>
        /// 调用递归获取物料类型数据
        /// </summary>
        /// <param name="materialTypeName"></param>
        /// <returns></returns>
        public async Task<JsonResult> GetMaterialType()
        {
            var typeTree = await _service.GetMaterialType();
            return Json(typeTree);
        }

        /// <summary>
        /// 物料新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> MaterialAdd(MaterialManagementAddDto model)
        {
            return await _service.MaterialAdd(model);
        }

        /// <summary>
        /// 获取所有物料数据
        /// </summary>
        /// <returns></returns>
        public async Task<List<MaterialManagement>> GetMaterialAll()
        {
            return await _service.GetMaterialAll();
        }

        /// <summary>
        /// 物料删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task<int> MaterialDelete(int id)
        {
            return await _service.MaterialDelete(id);
        }

        /// <summary>
        /// 获取单个物料
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task<MaterialManagement> GetSingMaterial(int id)
        {
            return await _service.GetSingMaterial(id);
        }

        /// <summary>
        /// 物料编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> MaterialUpdate(MaterialManagementUpdDto model)
        {
            return await _service.MaterialUpdate(model);
        }
    }
}
